package com.cleaningcloud.cld.service.impl;

import java.util.List;

import com.cleaningcloud.cld.domain.CldStaffComplaintReply;
import com.cleaningcloud.cld.domain.dto.CldStaffComplaintDto;
import com.cleaningcloud.cld.domain.vo.CldStaffComplaintVo;
import com.cleaningcloud.cld.mapper.CldStaffComplaintReplyMapper;
import com.cleaningcloud.common.core.utils.DateUtils;
import com.cleaningcloud.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cleaningcloud.cld.mapper.CldStaffComplaintMapper;
import com.cleaningcloud.cld.domain.CldStaffComplaint;
import com.cleaningcloud.cld.service.ICldStaffComplaintService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 员工投诉Service业务层处理
 * 
 * @author cleaningcloud
 * @date 2024-10-27
 */
@Service
public class CldStaffComplaintServiceImpl implements ICldStaffComplaintService 
{
    @Autowired
    private CldStaffComplaintMapper cldStaffComplaintMapper;

    @Autowired
    private CldStaffComplaintReplyMapper cldStaffComplaintReplyMapper;

    /**
     * 查询员工投诉
     * 
     * @param staffComplaintId 员工投诉主键
     * @return 员工投诉
     */
    @Override
    public CldStaffComplaintVo selectCldStaffComplaintByStaffComplaintId(Long staffComplaintId)
    {
        return cldStaffComplaintMapper.selectCldStaffComplaintByStaffComplaintId(staffComplaintId);
    }

    /**
     * 查询员工投诉列表
     * 
     * @param cldStaffComplaint 员工投诉
     * @return 员工投诉
     */
    @Override
    public List<CldStaffComplaintVo> selectCldStaffComplaintList(CldStaffComplaintDto cldStaffComplaint)
    {
        return cldStaffComplaintMapper.selectCldStaffComplaintList(cldStaffComplaint);
    }

    /**
     * 新增员工投诉
     * 
     * @param cldStaffComplaint 员工投诉
     * @return 结果
     */
    @Override
    public int insertCldStaffComplaint(CldStaffComplaint cldStaffComplaint)
    {
        cldStaffComplaint.setStaffId(SecurityUtils.getUserId());
        cldStaffComplaint.setComplaintTime(DateUtils.getNowDate());
        return cldStaffComplaintMapper.insertCldStaffComplaint(cldStaffComplaint);
    }

    @Override
    public int addReply(CldStaffComplaintReply cldStaffComplaintReply) {
        cldStaffComplaintReply.setReplyTime(DateUtils.getNowDate());
        cldStaffComplaintReply.setReplyUserId(SecurityUtils.getUserId());
        return cldStaffComplaintReplyMapper.insertCldStaffComplaintReply(cldStaffComplaintReply);
    }

    /**
     * 修改员工投诉
     * 
     * @param cldStaffComplaint 员工投诉
     * @return 结果
     */
    @Override
    public int updateCldStaffComplaint(CldStaffComplaint cldStaffComplaint)
    {
        return cldStaffComplaintMapper.updateCldStaffComplaint(cldStaffComplaint);
    }

    /**
     * 批量删除员工投诉
     * 
     * @param staffComplaintIds 需要删除的员工投诉主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteCldStaffComplaintByStaffComplaintIds(Long[] staffComplaintIds)
    {
        for (Long staffComplaintId : staffComplaintIds) {
            // 批量删除回复表
            cldStaffComplaintReplyMapper.deleteCldStaffComplaint(staffComplaintId);
        }
        return cldStaffComplaintMapper.deleteCldStaffComplaintByStaffComplaintIds(staffComplaintIds);
    }

    /**
     * 删除员工投诉信息
     * 
     * @param staffComplaintId 员工投诉主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteCldStaffComplaintByStaffComplaintId(Long staffComplaintId)
    {

        return cldStaffComplaintMapper.deleteCldStaffComplaintByStaffComplaintId(staffComplaintId);
    }
}
